***Foreign Fighters & Lethality in Civil Conflicts***
*Tricia Bacon & Alexander D. Clayton
*March 12, 2018

***Final .do file

**Load data (FFs & Lethality Data, B&C (final).dta)

*Summary Statistics (Table 2)
sum bdbest ff_local ff_distant ethcon intlcon gdpc_lag pop_lag ef_lag polity_lag bd_lag

*Correlation Matrix (Table 3
pwcorr bdbest ff_local ff_distant ethcon intlcon gdpc_lag pop_lag ef_lag polity_lag

*Correlation Matrix w/ significance
pwcorr bdbest ff_local ff_distant ethcon intlcon gdpc_lag pop_lag ef_lag polity_lag, sig

*Other Summary Statistics/Baseline differences (Table 4)
sum bdbest ethcon intlcon gdpc_lag pop_lag ef_lag polity_lag bd_lag if ff==0
sum bdbest ethcon intlcon gdpc_lag pop_lag ef_lag polity_lag bd_lag if ff_local==1
sum bdbest ethcon intlcon gdpc_lag pop_lag ef_lag polity_lag bd_lag if ff_distant==1
sum bdbest ethcon intlcon gdpc_lag pop_lag ef_lag polity_lag bd_lag if ff==0 & startyear==1
sum bdbest ethcon intlcon gdpc_lag pop_lag ef_lag polity_lag bd_lag if ff_local==1 & startyear==1
sum bdbest ethcon intlcon gdpc_lag pop_lag ef_lag polity_lag bd_lag if ff_distant==1 & startyear==1

***Regression Analyses
**Foreign Fighters as a single category (Model Set 1, Table 5A)
*Basic Model
tnbreg bdbest ff intlcon ethcon, vce(cluster conflictid)

*Partial Model w/ Controls
tnbreg bdbest ff intlcon ethcon lgdpc_lag lpop_lag ef_lag polity_lag lbd_lag, vce(cluster conflictid)

*Full Model w/ Controls, Conflict & Year Fixed Effects
tnbreg bdbest ff intlcon ethcon lgdpc_lag lpop_lag ef_lag polity_lag lbd_lag i.year i.conflictid, vce(cluster conflictid)

*Model fit, Margins, and Visualization (Figure 1)
estat ic
margins, dydx(ff intlcon ethcon)
marginsplot, yline(0)

**Foreign Fighters as two categories (Model Set 2, Table 5B)
*Basic Model
tnbreg bdbest ff_local ff_distant intlcon ethcon, vce(cluster conflictid)

*Partial Model w/ Controls
tnbreg bdbest ff_local ff_distant intlcon ethcon lgdpc_lag lpop_lag ef_lag polity_lag lbd_lag, vce(cluster conflictid) 

*Full Model w/ Controls, Conflict & Year Fixed Effects
tnbreg bdbest ff_local ff_distant intlcon ethcon lgdpc_lag lpop_lag ef_lag polity_lag lbd_lag i.year i.conflictid, vce(cluster conflictid)

*Model fit, Margins, and Visualization (Figure 2)
estat ic
margins, dydx(ff_local ff_distant intlcon ethcon)
marginsplot, yline(0)

***Robustness Checks and Sensitivity Analyses
**Robustness checks: Generalized linear models by "family" (Table 6)
*Negative binomial
glm bdbest ff_local ff_distant intlcon ethcon lgdpc_lag lpop_lag ef_lag polity_lag lbd_lag i.year i.conflictid, family(nb) vce(cluster conflictid)
estat ic
margins, dydx(ff_local ff_distant intlcon ethcon)
*Poisson
glm bdbest ff_local ff_distant intlcon ethcon lgdpc_lag lpop_lag ef_lag polity_lag lbd_lag i.year i.conflictid, family(p) vce(cluster conflictid)
estat ic
margins, dydx(ff_local ff_distant intlcon ethcon)
*Gamma
glm bdbest ff_local ff_distant intlcon ethcon lgdpc_lag lpop_lag ef_lag polity_lag lbd_lag i.year i.conflictid, family(gam) link(log) vce(cluster conflictid)
estat ic
margins, dydx(ff_local ff_distant intlcon ethcon)

**Robustness checks: Alternative estimates of the dependent variable (Table 7)
*bdlow
tnbreg bdlow ff_local ff_distant intlcon ethcon lgdpc_lag lpop_lag ef_lag polity_lag lbd_lag i.year i.conflictid, vce(cluster conflictid)
margins, dydx(ff_local ff_distant intlcon ethcon)
*bdhigh
tnbreg bdhigh ff_local ff_distant intlcon ethcon lgdpc_lag lpop_lag ef_lag polity_lag lbd_lag i.year i.conflictid, vce(cluster conflictid)
margins, dydx(ff_local ff_distant intlcon ethcon)

**Sensitivity Analyses (Table 8)
*Dropping cases > 5k ***CAUTION!!! DO NOT SAVE***
drop if bdbest > 5000
tnbreg bdbest ff_local ff_distant intlcon ethcon lgdpc_lag lpop_lag ef_lag polity_lag lbd_lag i.year i.conflictid, vce(cluster conflictid)
margins, dydx(ff_local ff_distant intlcon ethcon)

*Histogram distribution of bdbest, after dropping cases above 5k for ease of interpretation (Figure 3)
hist bdbest, freq bin(100) start(25)
*DON'T SAVE*
clear

*Reload Data to continue (FFs & Lethality Data, B&C (final).dta)

*Dropping cases < 1k ***CAUTION!!! DO NOT SAVE***
drop if bdbest < 1000
tnbreg bdbest ff_local ff_distant intlcon ethcon lgdpc_lag lpop_lag ef_lag polity_lag lbd_lag i.year i.conflictid, vce(cluster conflictid)
margins, dydx(ff_local ff_distant intlcon ethcon)
*DON'T SAVE*
clear


